package core.sceneManager.sceneSection.scene2DSection
{
	import core.sceneManager.sceneSection.AnimateSection;
	
	import flash.events.IEventDispatcher;
	import flash.media.Sound;
	import flash.media.SoundLoaderContext;
	import flash.net.URLRequest;
	
	import utils.MusicManager;

	public class SoundSection extends AnimateSection
	{
		private var url:String;                    //路径
		private var loops:int=1;                   //循环的次数
		private var _checkPolicyFile:Boolean=true;
		private const id:String="backGroundMusic"; //在MusicManager中的id
		private var position:Number=0;             //声音所在的位置
		public function SoundSection(target:IEventDispatcher=null)
		{
			super(target);
		}
		override public function start():void
		{
			MusicManager.getInstance().regedit(this.id,new Sound(new URLRequest(this.url),new SoundLoaderContext(1000,this._checkPolicyFile)));
			MusicManager.getInstance().playMusic(this.id,0,this.loops);
		}
		
		override public function pause():void
		{
			position=MusicManager.getInstance().soundStop(id);
		}
		
		override public function resume():void
		{
			MusicManager.getInstance().dispose(this.id);
			MusicManager.getInstance().regedit(this.id,new Sound(new URLRequest(this.url),new SoundLoaderContext(1000,this._checkPolicyFile)));
			MusicManager.getInstance().playMusic(this.id,position,this.loops);
		}
		override public function dispose():void
		{
			super.dispose();
			MusicManager.getInstance().dispose(this.id);
		}
		//////////////////////////////////////////声明属性，可以通过XML进行配置//////////////////
		private function set checkPolicyFile(val:int):void
		{
			if(val==1)
			{
				_checkPolicyFile=true;
			}else
			{
				_checkPolicyFile=false;
			}
		}
	}
}